package no.cicero.testframework.reporting;

import no.cicero.testframework.model.testcase.Step;

public class ReportingTestCase {
    private String testCaseName;
    private String testCaseDescription;
    private Reporting reporting;

    private int failedStepsCount = 0;
    private int totalStepsCount = 0;
    private ReportingStep currentStep = null;

    public ReportingTestCase(String testCaseName, String testCaseDescription, Reporting reporting) {
        this.testCaseName = testCaseName;
        this.testCaseDescription = testCaseDescription;
        this.reporting = reporting;
    }

     /**
     * Getter,Setter section
     */

	public Reporting getReporting() {return reporting;}
    public String getTestCaseName() {return testCaseName;}
    public String getTestCaseDescription() {return testCaseDescription;}
    public String getTestCaseFileName() {return testCaseName.replaceAll(".xml", "").toLowerCase();}
    public int getTotalStepsCount() {return totalStepsCount;}
    public int getFailedStepsCount() {return failedStepsCount;}
    public ReportingStep getCurrentStep() {return currentStep;}

    /**
     * This section implements all methods needed to work
     * with Step
     */
    public ReportingStep stepStart(Step step) {
        ++totalStepsCount;
        currentStep = new ReportingStep(step);

		reporting.notifyReportsNoThrow(new Reporting.MessageNoThrow<IReport>() {
			public void send(IReport obj) {
				obj.stepStarted(currentStep);
			}
		});

        return currentStep;
    }

    public void setStepSucceeded(){
		reporting.notifyReportsNoThrow(new Reporting.MessageNoThrow<IReport>() {
			public void send(IReport obj) {
				obj.stepSuccess(currentStep);
			}
		});

		currentStep = null;
    }
	
    public void setStepFailed(){
        ++failedStepsCount;

		reporting.notifyReportsNoThrow(new Reporting.MessageNoThrow<IReport>() {
			public void send(IReport obj) {
				obj.stepFailed(currentStep);
			}
		});

        currentStep = null;
    }
}
